
if( typeof LofSlideNews != Object ) {	
	Element.Events.extend({
		'wheelup': {
			type: Element.Events.mousewheel.type,
			map: function(event){
				event = new Event(event);
				if (event.wheel >= 0) this.fireEvent('wheelup', event)
			}
		},
		'wheeldown': {
			type: Element.Events.mousewheel.type,
			map: function(event){
				event = new Event(event);
				if (event.wheel <= 0) this.fireEvent('wheeldown', event)
			}
		}
	});
	var LofSlideNews = new Class( {
		initialize:function( eMain, options ){ 	 
			this.setting = Object.extend({
				mainItemClass		: '.lof-main-item',
				interval	  	 	:3000,
				fxObject: null
			}, options || {} );

			this.currentNo  = 0;
			this.nextNo     = null;
			this.previousNo = null;
			this.totalItems = 0;
			this.fxNavigatorImages=[];
			this.fxItems = [];
			this.maxWidth = 400;
			// 
			if( $defined(eMain) ){
				this.slides = eMain.getElements( this.setting.mainItemClass );
				this.totalItems = this.slides.length;
				if( 	this.totalItems <= 1 ){
					return ;
				}
				var te=this;
				fx =  Object.extend({waiting:true , onComplete:this.onComplete.bind(this)}, this.setting.fxObject );
				this.slides.each( function(item, index) {
					item.setStyles( {"left": index * this.maxWidth,"width":this.maxWidth,"display" : "block"} );
					//					   
					this.fxItems[index] = new Fx.Style( item, 'left', fx );
				}.bind(this) );
			}
			// starting work
		},
		registerTransition:function(){
			return this;
		},
		registerButtonsControl:function( eventHandler, objects ){
			if( $defined(objects) && this.totalItems > 1 ){
				for( var action in objects ){
					if( $defined(this[action.toString()])  && $defined(objects[action]) ){
						if( action.toString() == 'scrolling' ) { 
							this.registerScrollControl( objects[action] );
						} else {
							objects[action].addEvent( eventHandler, this[action.toString()].bind(this, true) );
						}
					}
				}
			}
			return this;	
		},
		start:function( isStart ){
			if( isStart ){this.play( this.setting.interval,'next', true );}
		},
		onComplete:function(){},	
		onProcessing:function( item, manual, start, end ){
			this.previousNo = this.currentNo + (this.currentNo>0 ? -1 : this.totalItems-1);
			this.nextNo 	= this.currentNo + (this.currentNo < this.totalItems-1 ? 1 : 1- this.totalItems);	
			
			return this;
		},
		finishFx:function( manual ){
			if( manual ) this.stop();
		},
		fxStart:function( index, start, end ){
			this.fxItems[index].stop().start( start , end );
			return this;
		},
		
		registerScrollControl:function( handlerBox ){
			handlerBox.addEvents({
				'wheelup': function(e) {
					e = new Event(e).stop(); 
					this.previous(true);
				}.bind(this),
				'wheeldown': function(e) {
					e = new Event(e).stop();
					this.next(true);
				}.bind(this)
			} );
			return this;
		},
		__call:function( method, params ){ return $defined(this[method]) ? this[method]( params ) : null; },
		next:function( manual ){
			this.currentNo += (this.currentNo < this.totalItems-1) ? 1 : (1 - this.totalItems);	
			this.onProcessing( null, manual, 0, this.maxWidth )
				.fxStart( this.currentNo,  this.maxWidth , 0 )
				.fxStart( this.previousNo, 0,  -this.maxWidth  )
				.finishFx( manual );
		},
		previous:function( manual ){

			this.currentNo += this.currentNo > 0 ? -1 : this.totalItems - 1;
			this.onProcessing( null, manual, -this.maxWidth, 0 )
				.fxStart( this.nextNo, 0, this.maxWidth )
				.fxStart( this.currentNo, -this.maxWidth, 0 )
				.finishFx( manual	);			
		},
		stop:function(){ $clear(this.isRun ); },
		play:function( delay, direction, wait ){
			this.stop(); 
			if(!wait){ this[direction](false); }
			this.isRun = this[direction].periodical(delay,this,false);
		}
	} );
}